#import <objc/objc-class.h> // We need this in order to dereference a Class
extern BOOL gOn;
@implementation HQApplication
+ (void)doNSAppInstancePose {
if (NSApp) {
// Swizzle our class object (and its meta-class) to be a subclass of the class that NSApp is a member of. This could be a real stupid thing to do if any instances were going to be created and our new superclass had ivars. But this situation is fairly controlled and no more instances of NSApplication subclasses should ever be created.
Class realNSAppClass = ((HQApplication *)NSApp)->isa;
Class hqAppClass = [HQApplication class];
Class realNSAppMetaClass = ((HQApplication *)realNSAppClass)->isa;
Class hqAppMetaClass = ((HQApplication *)hqAppClass)->isa;
hqAppClass->super_class = realNSAppClass;
hqAppMetaClass->super_class = realNSAppMetaClass;
// Swizzle NSApp into an instance of our subclass.
// We cast to HQApplication as a simple way to get around the fact that isa is @protected. It does not matter what we cast to, really, since everything has an isa.